home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 5 / Gold Medal Software - Volume 5 (Gold Medal) (1995).iso / database / cff51b.arj / DATATEST.C < prev    next >
C/C++ Source or Header  |  1993-10-22  |  17KB  |  686 lines

  1. /* DATATEST.C */
  2. /* Copyright 1990, 1991, 1992, 1993 Norman D. Culver Ft. Lauderdale, FL */
  3. /*                    All Rights Reserved                                   */
  4.  
  5. #include <stdlib.h>
  6. #include "../cff.h"
  7.  
  8. #define CLOCKS_PER_SECOND 1000000L
  9.  
  10. /* TEST CHOICES */
  11. #define PFLAGS 0
  12. #define MEMFILE 1
  13. #define EXTDMEM 1
  14. #define DOHASH 1
  15. #define DOTREE 1
  16.  
  17. extern int errno;
  18. extern long clock();
  19. extern int rand();
  20. static void data_test1(void *hd, void *hd1);
  21. static void data_test2(void *hd, void *hd1);
  22.  
  23. OPNINFO info;
  24.  
  25. void
  26. main()
  27. {
  28. void *hxxx;
  29. void *huniq;
  30. void *huniq1;
  31. void *huniq2;
  32. void *huniq3;
  33. void *hsxxx;
  34. void *hsxxx1;
  35. void *hsxxx2;
  36. void *hsxxx3;
  37.  
  38.     cfport_settestflags(1);
  39.     cfinit("datatest",512,NULL);
  40.     cfprintf("KEYED DATA STORAGE -- 128 bytes\n");
  41.  
  42.     /* SET UP PREALLOC FOR THE HASH DIRECTORIES */
  43.  
  44. #if MEMFILE
  45.     /* EXTRANEOUS DIRECTORY just to add flavor */
  46.     cfprintf("MEMORY FILE\n");
  47.     hxxx = cfopen("MEMORY/XXX",F_RDWR|F_CREAT,NULL);
  48.     if(!hxxx) {
  49.         cfprintf("ERROR: create XXX err=%d\n", errno);
  50.         exit(0);
  51.     }
  52.  
  53.     /* HASH DIRECTORY WITH PREALLOC OF MAPS AND DATA */
  54.     info.initial_entries = 1000;
  55.     info.bitmap_prealloc = 0;
  56.     info.data_prealloc = 128;
  57.     huniq = cfopen("MEMORY/XXX",
  58.                     F_RDWR|F_CREAT|F_TEMP|F_UNIQ|F_HUGEDIR, &info);
  59.     if(!huniq) {
  60.         cfprintf("ERROR: create UNIQUE TEMP FILE0 err=%d\n", errno);
  61.         exit(0);
  62.     }
  63.  
  64.     /* TREE DIRECTORY no prealloc */
  65.     huniq1 = cfopen("MEMORY/XXX",
  66.                     F_RDWR|F_CREAT|F_TEMP|F_UNIQ|F_SORTED, NULL);
  67.     if(!huniq1) {
  68.         cfprintf("ERROR: create UNIQUE TEMP FILE1 err=%d\n", errno);
  69.         exit(0);
  70.     }
  71.     /* HASH DIRECTORY WITH PREALLOC OF MAPS AND DATA */
  72.     info.initial_entries = 1000;
  73.     info.bitmap_prealloc = 0;
  74.     info.data_prealloc = 128;
  75.     huniq2 = cfopen("MEMORY/XXX",
  76.                     F_RDWR|F_CREAT|F_TEMP|F_UNIQ|F_HUGEDIR, &info);
  77.     if(!huniq2) {
  78.         cfprintf("ERROR: create UNIQUE TEMP FILE2 err=%d\n", errno);
  79.         exit(0);
  80.     }
  81.     /* TREE DIRECTORY no prealloc */
  82.     huniq3 = cfopen("MEMORY/XXX",
  83.                     F_RDWR|F_CREAT|F_TEMP|F_UNIQ|F_SORTED, NULL);
  84.     if(!huniq3) {
  85.         cfprintf("ERROR: create UNIQUE TEMP FILE3 err=%d\n", errno);
  86.         exit(0);
  87.     }
  88. #if PFLAGS
  89.     cfpflags("hxxx", hxxx);
  90.     cfpflags("huniq", huniq);
  91.     cfpflags("huniq1", huniq1);
  92.     cfpflags("huniq2", huniq2);
  93.     cfpflags("huniq3", huniq3);
  94. #endif
  95.  
  96.     cfsetverylazy(huniq);
  97.     cfsetverylazy(huniq1);
  98.     data_test1(huniq, huniq1);
  99.  
  100.     cfsetverylazy(huniq2);
  101.     cfsetverylazy(huniq3);
  102.     data_test2(huniq2, huniq3);
  103.  
  104. cfprintf("NOW CLOSING\n");
  105.     cfclose(huniq);
  106.     cfclose(huniq1);
  107.     cfclose(huniq2);
  108.     cfclose(huniq3);
  109. #endif /* MEMFILE */
  110.  
  111.  
  112. #if EXTDMEM
  113.     cfprintf("EXTDMEM FILE\n");
  114.  
  115.     /* HASH DIRECTORY WITH PREALLOC OF MAPS ONLY */
  116.     info.initial_entries = 1000;
  117.     info.bitmap_prealloc = 0;
  118.     info.data_prealloc = 0;
  119.     hsxxx = cfopen("EXTDMEM/XXX", F_RDWR|F_CREAT|F_HUGEDIR, &info);
  120.     if(!hsxxx) {
  121.         cfprintf("ERROR: create EXTDMEM/XXX err=%d\n", errno);
  122.         exit(0);
  123.     }
  124.  
  125.     /* TREE DIRECTORY no prealloc */
  126.     hsxxx1 = cfopen("EXTDMEM/XXX1", F_RDWR|F_CREAT|F_SORTED, NULL);
  127.     if(!hsxxx1) {
  128.         cfprintf("ERROR: create EXTDMEM/XXX1 err=%d\n", errno);
  129.         exit(0);
  130.     }
  131.  
  132.     /* HASH DIRECTORY WITH PREALLOC OF MAPS and DATA */
  133.     info.initial_entries = 1000;
  134.     info.bitmap_prealloc = 0;
  135.     info.data_prealloc = 128;
  136.     hsxxx2 = cfopen("EXTDMEM/XXX2", F_RDWR|F_CREAT|F_HUGEDIR, &info);
  137.     if(!hsxxx2) {
  138.         cfprintf("ERROR: create EXTDMEM/XXX2 err=%d\n", errno);
  139.         exit(0);
  140.     }
  141.  
  142.     /* TREE DIRECTORY no prealloc */
  143.     hsxxx3 = cfopen("EXTDMEM/XXX3", F_RDWR|F_CREAT|F_SORTED, NULL);
  144.     if(!hsxxx3) {
  145.         cfprintf("ERROR: create EXTDMEM/XXX3 err=%d\n", errno);
  146.         exit(0);
  147.     }
  148.  
  149. #if PFLAGS
  150.     cfpflags("hsxxx", hsxxx);
  151.     cfpflags("hsxxx1", hsxxx1);
  152.     cfpflags("hsxxx2", hsxxx2);
  153.     cfpflags("hsxxx3", hsxxx3);
  154. #endif
  155. #if 0
  156.     cfsetverylazy(hsxxx);
  157.     cfsetverylazy(hsxxx1);
  158. #endif
  159.     data_test1(hsxxx, hsxxx1);
  160.  
  161.     cfsetverylazy(hsxxx2);
  162.     cfsetverylazy(hsxxx3);
  163.     data_test2(hsxxx2, hsxxx3);
  164.  
  165. cfprintf("NOW CLOSING\n");
  166.     cfclose(hsxxx);
  167.     cfclose(hsxxx1);
  168.     cfclose(hsxxx2);
  169.     cfclose(hsxxx3);
  170.  
  171.     cfprintf("REOPEN EXTDMEM FILE\n");    
  172.     hsxxx = cfopen("EXTDMEM/XXX", F_RDWR, NULL);
  173.     if(!hsxxx) {
  174.         cfprintf("ERROR: reopen EXTDMEM:/XXX err=%d\n", errno);
  175.         exit(0);
  176.     }
  177.     hsxxx1 = cfopen("EXTDMEM/XXX1", F_RDWR, NULL);
  178.     if(!hsxxx1) {
  179.         cfprintf("ERROR: reopen EXTDMEM:/XXX1 err=%d\n", errno);
  180.         exit(0);
  181.     }
  182.     hsxxx2 = cfopen("EXTDMEM/XXX2", F_RDWR, NULL);
  183.     if(!hsxxx2) {
  184.         cfprintf("ERROR: reopen EXTDMEM:/XXX2 err=%d\n", errno);
  185.         exit(0);
  186.     }
  187.     hsxxx3 = cfopen("EXTDMEM/XXX3", F_RDWR, NULL);
  188.     if(!hsxxx3) {
  189.         cfprintf("ERROR: reopen EXTDMEM:/XXX3 err=%d\n", errno);
  190.         exit(0);
  191.     }
  192. #if 0
  193.     cfsetverylazy(hsxxx);
  194.     cfsetverylazy(hsxxx1);
  195. #endif
  196.     data_test1(hsxxx,hsxxx1);
  197.  
  198.     cfsetverylazy(hsxxx2);
  199.     cfsetverylazy(hsxxx3);
  200.     data_test2(hsxxx2,hsxxx3);
  201.  
  202. cfprintf("NOW UNLINKING\n");
  203.     cfunlink(hsxxx, NULL);
  204.     cfunlink(hsxxx1, NULL);
  205.     cfunlink(hsxxx2, NULL);
  206.     cfunlink(hsxxx3, NULL);
  207. #endif /* EXTDMEM */
  208.  
  209.     cfexit();
  210. } /* END: MAIN */
  211.  
  212. char *lkey1 = "this is a long key";
  213. static long buf[32];
  214. static Item loc;
  215. static Item dupval;
  216.  
  217. static void
  218. data_test1(void *hd, void *hd1)
  219. {
  220. long i, start, end, diff, result;
  221. long varkey[32];
  222.  
  223.     cfprintf("Begin data_test1 -- 128 bytes per item\n");
  224.  
  225. #if 0
  226. cfprintf("BEFORE\n");
  227. print_entries(hd1);
  228. print_all_bitmaps(hd1);
  229. #endif
  230.  
  231.  
  232. #if DOHASH == 1
  233.  
  234.     start = clock();
  235.     for (i = 0; i < 100; ++i)
  236.     {
  237.         buf[0] = i+6;
  238.         buf[31] = i+9;
  239.         if(!(cfput_dupnum(hd, lkey1, strlen(lkey1), buf, 128, &loc, &dupval))) {
  240.             cfprintf("PUTDATA dupnum hash failed at i=%d\n", i);
  241.             break;
  242.         }
  243.         if(dupval.a0 != i+1)
  244.             cfprintf("PUTDATA dupnum hash dupval=%d should be %d\n", dupval.a0, i+1);
  245.     }
  246.     end = clock();
  247.     diff = end - start;
  248.     diff /= CLOCKS_PER_SECOND/10;
  249.     if(diff == 0) diff = 1;
  250.     cfprintf("  PUTDATA dupnum hash PER SEC = %ld\n", (i*10) / diff);
  251.  
  252.     start = clock();
  253.     for (i = 0; i < 100; ++i)
  254.     {
  255.         dupval.a0 = i;
  256.         if((result = cfget_dupnum(hd, lkey1, strlen(lkey1), buf, 128, &dupval)) < FOUND) {
  257.             cfprintf("GETDATA dupnum hash failed result = %d\n", result);
  258.             break;
  259.         }
  260.         if(buf[0] != i+6 || buf[31] != i+9)
  261.             cfprintf("GETDATA dupnum hash returned wrong value %d should be %d\n",
  262.             buf[0], i+6);
  263.     }
  264.     end = clock();
  265.     diff = end - start;
  266.     diff /= CLOCKS_PER_SECOND/10;
  267.     if(diff == 0) diff = 1;
  268.     cfprintf("  GETDATA dupnum hash PER SEC = %ld\n", (i*10) / diff);
  269.  
  270.     start = clock();
  271.     for (i = 99; i >= 0; --i)
  272.     {
  273.  
  274.         if((result = cfdelete_dupnum(hd, lkey1, strlen(lkey1), i)) != OK) {
  275.             cfprintf("DELETE dupnum hash failed i=%d result = %d\n", i, result);
  276.             break;
  277.         }
  278.     }
  279.     end = clock();
  280.     diff = end - start;
  281.     diff /= CLOCKS_PER_SECOND/10;
  282.     if(diff == 0) diff = 1;
  283.     cfprintf("  DELETE dupnum hash PER SEC = %ld\n", (100*10) / diff);
  284.  
  285.     /* LONG KEY W/CHANGES */
  286.     strcpy((char *)varkey, lkey1);    
  287.     start = clock();
  288.     for (i = 0; i < 1000; ++i)
  289.     {
  290.         buf[0] = i+11;
  291.         buf[31] = i+23;
  292.         ++varkey[0];
  293.         if(!(cfput(hd, varkey, 16, buf, 128, &loc))) {
  294.             cfprintf("PUTDATA longkey hash failed at i=%d\n", i);
  295.             break;
  296.         }
  297.     }
  298.     end = clock();
  299.     diff = end - start;
  300.     diff /= CLOCKS_PER_SECOND/10;
  301.     if(diff == 0) diff = 1;
  302.     cfprintf("  PUTDATA longkey hash PER SEC = %ld\n", (i*10) / diff);
  303.  
  304.  
  305.     strcpy((char *)varkey, lkey1);    
  306.     start = clock();
  307.     for (i = 0; i < 1000; ++i)
  308.     {
  309.         ++varkey[0];
  310.         if((result = cfget(hd, varkey, 16, buf, 128)) != FOUND) {
  311.             cfprintf("GETDATA longkey hash failed result = %d i=%d x=%lx\n", result, i, varkey[0]);
  312.             break;
  313.         }
  314.         if(buf[0] != i+11 || buf[31] != i+23)
  315.             cfprintf("GETDATA longkey hash returned wrong value %d should be %d\n",
  316.             buf[0], i+11);
  317.     }
  318.     end = clock();
  319.     diff = end - start;
  320.     diff /= CLOCKS_PER_SECOND/10;
  321.     if(diff == 0) diff = 1;
  322.     cfprintf("  GETDATA longkey hash PER SEC = %ld\n", (i*10) / diff);
  323.  
  324.     strcpy((char *)varkey, lkey1);
  325.     start = clock();
  326.     for (i = 0; i < 1000; ++i)
  327.     {
  328.         ++varkey[0];
  329.         if((result = cfdelete(hd, varkey, 16)) != OK) {
  330.             cfprintf("DELETE longkey hash failed result = %d i=%d\n", result, i);
  331.             break;
  332.         }
  333.     }
  334.     end = clock();
  335.     diff = end - start;
  336.     diff /= CLOCKS_PER_SECOND/10;
  337.     if(diff == 0) diff = 1;
  338.     cfprintf("  DELETE longkey hash PER SEC = %ld\n", (i*10) / diff);
  339.  
  340.  
  341.     /* SHORT KEY W/CHANGES */
  342.     start = clock();
  343.     varkey[0] = 1;
  344.     varkey[1] = 1;
  345.     for (i = 0; i < 1000; ++i)
  346.     {
  347.         buf[0] = i+16;
  348.         buf[31] = i+13;
  349.         ++varkey[0];
  350.         if(!(cfput(hd, varkey, 8, buf, 128, &loc))) {
  351.             cfprintf("PUTDATA shortkey hash failed at i=%d\n", i);
  352.             break;
  353.         }
  354.     }
  355.     end = clock();
  356.     diff = end - start;
  357.     diff /= CLOCKS_PER_SECOND/10;
  358.     if(diff == 0) diff = 1;
  359.     cfprintf("  PUTDATA shortkey hash PER SEC = %ld\n", (i*10) / diff);
  360.  
  361.  
  362.     varkey[0] = 1;
  363.     varkey[1] = 1;
  364.     start = clock();
  365.     for (i = 0; i < 1000; ++i)
  366.     {
  367.         ++varkey[0];
  368.         if((result = cfget(hd, varkey, 8, buf, 128)) != FOUND) {
  369.             cfprintf("GETDATA shortkey hash failed result = %d i=%d\n", result, i);
  370.             break;
  371.         }
  372.         if(buf[0] != i+16 || buf[31] != i+13)
  373.             cfprintf("GETDATA shortkey hash returned wrong value %d should be %d\n",
  374.             buf[0], i+16);
  375.     }
  376.     end = clock();
  377.     diff = end - start;
  378.     diff /= CLOCKS_PER_SECOND/10;
  379.     if(diff == 0) diff = 1;
  380.     cfprintf("  GETDATA shortkey hash PER SEC = %ld\n", (i*10) / diff);
  381.  
  382.     varkey[0] = 1;
  383.     varkey[1] = 1;
  384.     start = clock();
  385.     for (i = 0; i < 1000; ++i)
  386.     {
  387.         ++varkey[0];
  388.         if((result = cfdelete(hd, varkey, 8)) != OK) {
  389.             cfprintf("DELETE shortkey hash failed result = %d i=%d\n", result,i);
  390.             break;
  391.         }
  392.     }
  393.     end = clock();
  394.     diff = end - start;
  395.     diff /= CLOCKS_PER_SECOND/10;
  396.     if(diff == 0) diff = 1;
  397.     cfprintf("  DELETE shortkey hash PER SEC = %ld\n", (i*10) / diff);
  398.  
  399. #endif
  400. #if DOTREE == 1
  401.  
  402.     start = clock();
  403.     for (i = 0; i < 100; ++i)
  404.     {
  405.         buf[0] = i+45;
  406.         buf[31] = i+93;
  407.         if(!(cfput_dupnum(hd1, lkey1, strlen(lkey1), buf, 128, &loc, &dupval))) {
  408.             cfprintf("PUTDATA dupnum tree failed at i=%d\n", i);
  409.             break;
  410.         }
  411.         if(dupval.a0 != i+1)
  412.             cfprintf("PUTDATA dupnum tree dupval=%d should be %d\n", dupval.a0, i+1);
  413.     }
  414.     end = clock();
  415.     diff = end - start;
  416.     diff /= CLOCKS_PER_SECOND/10;
  417.     if(diff == 0) diff = 1;
  418.     cfprintf("  PUTDATA dupnum tree PER SEC = %ld\n", (i*10) / diff);
  419.  
  420.     start = clock();
  421.     for (i = 0; i < 100; ++i)
  422.     {
  423.         dupval.a0 = i;
  424.         if((result = cfget_dupnum(hd1, lkey1, strlen(lkey1), buf, 128, &dupval)) < FOUND) {
  425.             cfprintf("GETDATA dupnum tree failed result = %d\n", result);
  426.             break;
  427.         }
  428. #if 0    /* THIS WILL NOT ALWALYS BE TRUE -- SORTED DIRECTORIES sort the items */
  429.         if(buf[0] != i+45 || buf[31] != i+93)
  430.             cfprintf("GETDATA dupnum tree returned wrong value %d should be %d\n",
  431.             buf[0], i+45);
  432. #endif
  433.     }
  434.     end = clock();
  435.     diff = end - start;
  436.     diff /= CLOCKS_PER_SECOND/10;
  437.     if(diff == 0) diff = 1;
  438.     cfprintf("  GETDATA dupnum tree PER SEC = %ld\n", (i*10) / diff);
  439.  
  440.     start = clock();
  441.     for (i = 99; i >=0; --i)
  442.     {
  443.         if((result = cfdelete_dupnum(hd1, lkey1, strlen(lkey1), i)) != OK) {
  444.             cfprintf("DELETE dupnum tree i=%d failed result = %d\n", i, result);
  445.             break;
  446.         }
  447.     }
  448.     end = clock();
  449.     diff = end - start;
  450.     diff /= CLOCKS_PER_SECOND/10;
  451.     if(diff == 0) diff = 1;
  452.     cfprintf("  DELETE dupnum tree PER SEC = %ld\n", (100*10) / diff);
  453.  
  454.     /* LONG KEY W/CHANGES */
  455.     strcpy((char *)varkey, lkey1);    
  456.     start = clock();
  457.     for (i = 0; i < 1000; ++i)
  458.     {
  459.         buf[0] = i+76;
  460.         buf[31] = i+37;
  461.         ++varkey[0];
  462.         if(!(cfput(hd1, varkey, 16, buf, 128, &loc))) {
  463.             cfprintf("PUTDATA longkey tree failed at i=%d\n", i);
  464.             break;
  465.         }
  466.     }
  467.     end = clock();
  468.     diff = end - start;
  469.     diff /= CLOCKS_PER_SECOND/10;
  470.     if(diff == 0) diff = 1;
  471.     cfprintf("  PUTDATA longkey tree PER SEC = %ld\n", (i*10) / diff);
  472.  
  473.  
  474.     strcpy((char *)varkey, lkey1);    
  475.     start = clock();
  476.     for (i = 0; i < 1000; ++i)
  477.     {
  478.         ++varkey[0];
  479.         if((result = cfget(hd1, varkey, 16, buf, 128)) != FOUND) {
  480.             cfprintf("GETDATA longkey tree failed result = %d i=%d\n", result,i);
  481.             break;
  482.         }
  483.         if(buf[0] != i+76 || buf[31] != i+37)
  484.             cfprintf("GETDATA longkey tree returned wrong value %d should be %d\n",
  485.             buf[0], i+76);
  486.     }
  487.     end = clock();
  488.     diff = end - start;
  489.     diff /= CLOCKS_PER_SECOND/10;
  490.     if(diff == 0) diff = 1;
  491.     cfprintf("  GETDATA longkey tree PER SEC = %ld\n", (i*10) / diff);
  492.  
  493.     strcpy((char *)varkey, lkey1);
  494.     start = clock();
  495.     for (i = 0; i < 1000; ++i)
  496.     {
  497.         ++varkey[0];
  498.         if((result = cfdelete(hd1, varkey, 16)) != OK) {
  499.             cfprintf("DELETE longkey tree failed result = %d i=%d\n", result,i);
  500.             break;
  501.         }
  502.     }
  503.     end = clock();
  504.     diff = end - start;
  505.     diff /= CLOCKS_PER_SECOND/10;
  506.     if(diff == 0) diff = 1;
  507.     cfprintf("  DELETE longkey tree PER SEC = %ld\n", (i*10) / diff);
  508.  
  509.  
  510.     /* SHORT KEY W/CHANGES */
  511.     start = clock();
  512.     varkey[0] = 1;
  513.     varkey[1] = 1;
  514.     for (i = 0; i < 1000; ++i)
  515.     {
  516.         buf[0] = i+25;
  517.         buf[31] = i+35;
  518.         ++varkey[0];
  519.         if(!(cfput(hd1, varkey, 8, buf, 128, &loc))) {
  520.             cfprintf("PUTDATA shortkey tree failed at i=%d\n", i);
  521.             break;
  522.         }
  523.     }
  524.     end = clock();
  525.     diff = end - start;
  526.     diff /= CLOCKS_PER_SECOND/10;
  527.     if(diff == 0) diff = 1;
  528.     cfprintf("  PUTDATA shortkey tree PER SEC = %ld\n", (i*10) / diff);
  529.  
  530.  
  531.     varkey[0] = 1;
  532.     varkey[1] = 1;
  533.     start = clock();
  534.     for (i = 0; i < 1000; ++i)
  535.     {
  536.         ++varkey[0];
  537.         if((result = cfget(hd1, varkey, 8, buf, 128)) != FOUND) {
  538.             cfprintf("GETDATA shortkey tree failed result = %d i=%d\n", result,i);
  539.             break;
  540.         }
  541.         if(buf[0] != i+25 || buf[31] != i+35)
  542.             cfprintf("GETDATA shortkey tree returned wrong value %d should be %d\n",
  543.             buf[0], i+25);
  544.     }
  545.     end = clock();
  546.     diff = end - start;
  547.     diff /= CLOCKS_PER_SECOND/10;
  548.     if(diff == 0) diff = 1;
  549.     cfprintf("  GETDATA shortkey tree PER SEC = %ld\n", (i*10) / diff);
  550.  
  551.     varkey[0] = 1;
  552.     varkey[1] = 1;
  553.     start = clock();
  554.     for (i = 0; i < 1000; ++i)
  555.     {
  556.         ++varkey[0];
  557.         if((result = cfdelete(hd1, varkey, 8)) != OK) {
  558.             cfprintf("DELETE shortkey tree failed result = %d i=%d\n", result,i);
  559.             break;
  560.         }
  561.     }
  562.     end = clock();
  563.     diff = end - start;
  564.     diff /= CLOCKS_PER_SECOND/10;
  565.     if(diff == 0) diff = 1;
  566.     cfprintf("  DELETE shortkey tree PER SEC = %ld\n", (i*10) / diff);
  567.  
  568. #endif
  569.  
  570. #if 0
  571. cfprintf("AFTER\n");
  572. print_entries(hd1);
  573. print_all_bitmaps(hd1);
  574. #endif
  575.  
  576.     cfprintf("End data_test1\n");
  577. }
  578. static void
  579. data_test2(void *hd, void *hd1)
  580. {
  581. long i, start, end, diff, result;
  582. DupName dupname;
  583. DupName savnam;
  584.  
  585.     cfprintf("Begin data_test2 DUPNAMES -- 128 bytes per item\n");
  586.  
  587. #if DOHASH == 1
  588.  
  589.     start = clock();
  590.     for (i = 0; i < 1000; ++i)
  591.     {
  592.         buf[0] = i+42;
  593.         buf[31] = i+43;
  594.         if(!(cfput_dupname(hd,"ADDRESS + PHONE NUMBER",22,buf,128,&loc,NULL)))
  595.             cfprintf("PUT dupname  hash failed at i=%d\n", i);
  596.     }
  597.     end = clock();
  598.     diff = end - start;
  599.     diff /= CLOCKS_PER_SECOND/10;
  600.     if(diff == 0) diff = 1;
  601.     cfprintf("  PUT DUPNAME hash PER SEC = %ld\n", (i*10) / diff);
  602.  
  603.  
  604.     cflastdupname(hd, "ADDRESS + PHONE NUMBER", 22, &dupname);
  605.     start = clock();
  606.     for (i = 999; i >= 0; --i)
  607.     {
  608.         if(!(cfget_dupname(hd, &dupname, buf, 128)))
  609.             cfprintf("GET dupname  hash failed at i=%d\n", i);
  610.         if(buf[0] != i+42 || buf[31] != i+43)
  611.             cfprintf("GET dupname hash returned wrong value %d should be %d\n",
  612.             buf[0], i+42);
  613.         --dupname.name;
  614.     }
  615.     end = clock();
  616.     diff = end - start;
  617.     diff /= CLOCKS_PER_SECOND/10;
  618.     if(diff == 0) diff = 1;
  619.     cfprintf("  GET DUPNAME hash PER SEC = %ld\n", (1000*10) / diff);
  620.  
  621.     for (i = 0; i < 1000; ++i)
  622.     {
  623.         if((result = cfdelete_lastdupname(hd, "ADDRESS + PHONE NUMBER", 22)) != OK)
  624.             cfprintf("DELETE LASTDUPNAME hash failed at i=%d result=%d\n",
  625.              i, result);
  626.     }
  627.     end = clock();
  628.     diff = end - start;
  629.     diff /= CLOCKS_PER_SECOND/10;
  630.     if(diff == 0) diff = 1;
  631.     cfprintf("  DELETE LASTDUPNAME hash PER SEC = %ld\n", (i*10) / diff);
  632.  
  633. #endif
  634. #if DOTREE == 1
  635.  
  636.     start = clock();
  637.     for (i = 0; i < 1000; ++i)
  638.     {
  639.         buf[0] = i+42;
  640.         buf[31] = i+43;
  641.         if(!(cfput_dupname(hd1,"ADDRESS + PHONE NUMBER",22,buf,128,&loc,&savnam)))
  642.             cfprintf("PUT dupname tree failed at i=%d\n", i);
  643.     }
  644.     end = clock();
  645.     diff = end - start;
  646.     diff /= CLOCKS_PER_SECOND/10;
  647.     if(diff == 0) diff = 1;
  648.     cfprintf("  PUT DUPNAME tree PER SEC = %ld\n", (i*10) / diff);
  649.  
  650.     start = clock();
  651.  
  652.     cflastdupname(hd1, "ADDRESS + PHONE NUMBER", 22, &dupname);
  653.     for (i = 999; i >= 0; --i)
  654.     {
  655.         if(!(cfget_dupname(hd1, &dupname, buf, 128)))
  656.             cfprintf("GET dupname tree failed at i=%d\n", i);
  657.         if(buf[0] != i+42 || buf[31] != i+43)
  658.             cfprintf("GET dupname tree returned wrong value %d should be %d\n",
  659.             buf[0], i+42);
  660.         --dupname.name;
  661.     }
  662.     end = clock();
  663.     diff = end - start;
  664.     diff /= CLOCKS_PER_SECOND/10;
  665.     if(diff == 0) diff = 1;
  666.     cfprintf("  GET DUPNAME tree PER SEC = %ld\n", (1000*10) / diff);
  667.  
  668.     for (i = 0; i < 1000; ++i)
  669.     {
  670.         if((result = cfdelete_lastdupname(hd1, "ADDRESS + PHONE NUMBER", 22)) != OK)
  671.             cfprintf("DELETE LASTDUPNAME tree failed at i=%d result=%d\n",
  672.              i, result);
  673.     }
  674.     end = clock();
  675.     diff = end - start;
  676.     diff /= CLOCKS_PER_SECOND/10;
  677.     if(diff == 0) diff = 1;
  678.     cfprintf("  DELETE LASTDUPNAME tree PER SEC = %ld\n", (i*10) / diff);
  679.  
  680.  
  681. #endif
  682.  
  683.     cfprintf("End data_test2\n");
  684. }
  685.  
  686.